package at.austria.leecher.pages;

import at.austria.leecher.config.LeecherConfig;
import org.openqa.selenium.WebDriver;

public abstract class LeecherPage {

    protected WebDriver driver;
    private final Long beginMillis;
    private Long endMillis;

    protected Exception occuredException;

    protected LeecherPage() {
        this.beginMillis = System.currentTimeMillis();
        this.driver = LeecherConfig.newWebDriver();
    }

    public void finish() {
        this.endMillis = System.currentTimeMillis();
        if ( driver != null ) {
            driver.quit();
        }
        // wake up all other pages that wait on this page
        // this.notifyAll();
    }

    public boolean completedSuccessfully() {
        return occuredException == null;
    }

    public long getDuration() {
        return ( endMillis != null ? endMillis : System.currentTimeMillis() ) - beginMillis;
    }

    public abstract void start() throws Exception;

    @Override
    public String toString() {
        return String.format( "Duration: %d msec", this.getDuration() );
    }
}
